package com.testing.sunnyserver.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Classname SunnyAsyncConfiguration
 * @Description 类型说明
 * @Date 2023/5/19 20:13
 * @Created by 特斯汀Roy
 */
@Configuration
@EnableAsync
public class SunnyServerAsyncConfiguration {
    //编写一个自定义的线程池
    @Bean
    @Primary
    public TaskExecutor autoTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(50);
        executor.setMaxPoolSize(200);
        executor.setQueueCapacity(200);
        executor.setThreadNamePrefix("【平台端】自动化测试执行线程-");
        //设置拒绝策略为拒绝的时候谁调用谁负责执行
        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        //等待所有线程结束之后才关闭线程池
        executor.setWaitForTasksToCompleteOnShutdown(true);
        return executor;
    }


}
